package com.woniuxy.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.dao.PositionDao;
import com.woniuxy.entity.Organization;
import com.woniuxy.entity.Position;
import com.woniuxy.entity.ResponseEntity;
import com.woniuxy.service.PositionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PositionServiceImpl implements PositionService {
    @Autowired(required = false)
    PositionDao positionDao;

    @Override
    public ResponseEntity findAll() {
        List<Position> list = positionDao.findAll();
        return new ResponseEntity(200,"查询岗位成功",list);
    }

    @Override
    public ResponseEntity deleteOne(int id) {
        if(positionDao.deleteOne(id) > 0){
            return ResponseEntity.SUCCESS;
        }
        return ResponseEntity.Fail;
    }

    @Override
    public ResponseEntity addOne(Position position) {
        if(positionDao.addOne(position) > 0){
            return ResponseEntity.SUCCESS;
        }
        return ResponseEntity.Fail;
    }

    @Override
    public ResponseEntity findByContext(Position position) {
        List<Position> list = positionDao.findByContext(position);
        return new ResponseEntity(200,"查询指定内容成功",list);
    }

    @Override
    public ResponseEntity batchDelete(int[] ids) {
        if(positionDao.batchDelete(ids) > 0){
            return ResponseEntity.SUCCESS;
        }
        return ResponseEntity.Fail;
    }

    @Override
    public ResponseEntity findAll(int currentPage, int pageSize) {
        PageHelper.startPage(currentPage,pageSize);
        List<Position> list = positionDao.findAll();
        PageInfo<Position> pageInfo = PageInfo.of(list);
        return new ResponseEntity(200,"查询总数成功",pageInfo);
    }

    @Override
    public ResponseEntity updateOne(Position position) {
        if(positionDao.updateOne(position) > 0){
            return ResponseEntity.SUCCESS;
        }
        return ResponseEntity.Fail;
    }
}
